<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ include file="/page/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp"%>
<link
	href="${pageContext.request.contextPath}/frontframe/easyui/themes/easyui-extend.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript">
	//将参数里的&号转为~号
	function save() {
		var str_data = $("#form1 input").map(function() {
			return ($(this).attr("name") + '=' + $(this).val().replace(/&/g,"~"));
		}).get().join("&");
		$.ajax({
			url : "${ctx}/appWxMenuConfig/addWxMenuConfig",
			type : "POST",
			dataType : "json",
			data : str_data,
			async : false,
			success : function(data) {
				if (data.flag > 0) {
					alert("保存成功！");
					//window.location.reload();
				}
				/* 	          $.each(data, function(index, element) {
				 window.location.reload();
				 }); */
			},
			error : function() {
				alert("error");
			}
		});

	}

	function changeValue(Value, tagname) {
		document.getElementById(tagname).value = Value;
	}

	function goBack() {
		window.history.back(-1);
	}
	
	
	//用一个隐藏的input和select联动来实现选择使用挡板
	 function changetype(aThis){
			document.getElementById("wx_menu_type").value=aThis.value;
			if(aThis.value=="1"){
				$("#wx_menu_url").attr("disabled",false);
				$("#wx_resp_actionid").attr("disabled",true);
				$("#wx_event_key").attr("disabled",true);
			}else{
				$("#wx_menu_url").attr("disabled",true);
				$("#wx_resp_actionid").attr("disabled",false);
				$("#wx_event_key").attr("disabled",false);
			}
	}
	 //页面加载时给select预选值
	window.onload=function(){
		var menu_type="0";
		document.getElementById("wx_menu_type").value=menu_type;
		var all_options = document.getElementById("type_select").options;
		for (var i=0; i<all_options.length; i++){
			if (all_options[i].value == menu_type){
				all_options[i].selected = true;
			}
		}
		$("#wx_menu_url").attr("disabled",true);
	}
	
</script>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title">微信菜单配置</h3>
		</div>
		<div class="panel-body">
			<form class="form-horizontal" role="form" id="form1">
				<div class="form-group">
					<label class="col-xs-2 control-label" for="wx_menu_id">菜单ID</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_menu_id" name="wx_menu_id"
							type="text" placeholder="第一位是父菜单id，第二位是序号" />
					</div>
					<label class="col-xs-2 control-label" for="wx_menu_name">菜单名</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_menu_name" name="wx_menu_name"
							type="text" placeholder="菜单显示的名字" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label" for="parent_menu_id">父菜单ID</label>
					<div class="col-xs-4">
						<input class="form-control" id="parent_menu_id"
							name="parent_menu_id" type="text" placeholder="起始值为“0”" />
					</div>
					<label class="col-xs-2 control-label" for="wx_menu_rank">序号</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_menu_rank" name="wx_menu_rank"
							type="text" placeholder="起始值为“0”" />
					</div>
				</div>
				<div class="form-group">
					
					
						<label class="col-xs-2 control-label" for="wx_menu_type">菜单类型</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="wx_menu_type" name="wx_menu_type" type="hidden" />
                             <select id="type_select"  onchange="changetype(this)" class="form-control">
                             	<option value='0' >事件类型</option>
                             	<option value='1'>超链接类型</option>
                             </select>
                          </div> 
                          <label class="col-xs-2 control-label" for="app_id">APPID</label>
					<div class="col-xs-4">
						<input class="form-control" id="app_id" name="app_id" type="text" value="${appid}"  readonly="readonly" />
					</div>
					
					<!-- <label class="col-xs-2 control-label" for="wx_menu_type">菜单类型</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_menu_type" name="wx_menu_type" type="text" placeholder="" />
					</div>
					 -->
				</div>
				
				<div class="form-group">
					<label class="col-xs-2 control-label" for="wx_resp_actionid">响应动作编号</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_resp_actionid"
							name="wx_resp_actionid" type="text" placeholder="事件类型必填，与事件推送值相同" />
					</div>
					<label class="col-xs-2 control-label" for="wx_event_key">微信事件推送值</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_event_key" name="wx_event_key"
							type="text" placeholder="事件类型必填，与响应编号值相同" />
					</div>
					
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label" for="wx_menu_url">菜单链接</label>
					<div class="col-xs-4">
						<input class="form-control" id="wx_menu_url" name="wx_menu_url"
							type="text" placeholder="超链接类型必填" />
					</div>
				</div>
				<div class="form-group  text-center">
					<button type="button" class="btn btn-default" onclick="save();">保存</button>
					<button type="button" class="btn btn-default" onclick="goBack()">返回</button>
				</div>
			</form>
		</div>
	</div>

</body>
</html>
